<template>

  <div class="container-fuild">
    <div class="row page-titles">
      <ol class="breadcrumb">
        <li class="breadcrumb-item active">实训班 /</li>
        <li class="breadcrumb-item">教师实训班文档</li>
      </ol>
    </div>
    <div class="row">
      <div class="card">
        <div class="card-header">
          <p class="card-title">文档查看</p>
        </div>
        <div class="card-body custom-ekeditor">
          <div id="ckeditor">

            <el-table
                :data="tableData"
                style="width: 100% ;color: #7d94c0">
              <el-table-column
                  prop="className"
                  label="实训班"
                  width="280">
                <template slot-scope="scope">
                  <i class="el-icon-user"></i>
                  <span style="margin-left: 10px">{{ scope.row.className }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="开始日期"
                  width="160">
                <template slot-scope="scope">
                  <i class="el-icon-time"></i>
                  <span style="margin-left: 10px">{{ scope.row.startTime }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="结束日期"
                  width="160">
                <template slot-scope="scope">
                  <i class="el-icon-time"></i>
                  <span style="margin-left: 10px">{{ scope.row.endTime }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="期数"
                  width="160">
                <template slot-scope="scope">
                  <span style="margin-left: 0px">{{ scope.row.period }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="查看文档"
                  width="160">
                <template slot-scope="scope">
                  <el-button size="mini" style="background-color: steelblue ;color: white"
                             @click="tableShow(scope.$index, scope.row)">查看
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-drawer
                title="教师实训文档下载"
                :visible.sync="drawer">

              <div v-for="(item,index) in tableList" :key="index">
                <template>
                  <el-container>
                    <el-aside width="250px" style="padding: 10px;padding-left: 30px;display: inline-block;vertical-align: middle;text-align: left">

                      <p style="font-weight: bold;font-size: 10px;color: rgb(6 44 71)" >
                        {{ item.documentName}}
                      </p>
                      <p style="font-weight: bold;font-size: 10px;color: rgb(6 44 71)">
                        {{ item.loadTime }}
                      </p>
                    </el-aside>
                    <el-main>
                      <el-row type="flex" justify="center" style="padding-top: 8px;padding-right: 1px">
                        <el-button style="color: white;background-color: #ffe3b4;border-color: #ffe3b4" round size="mini" type="info" icon="el-icon-download" circle
                                   @click="download(item.afterLoadName,item.documentName)"></el-button>
                      </el-row>
                    </el-main>
                  </el-container>
                </template>

              </div>

            </el-drawer>

          </div>
        </div>
      </div>
    </div>


  </div>

</template>

<script>

export default {
  name: "TeacherDoc",
  data() {
    return {
      id:this.$route.query.id,
      dialogVisible: false,
      tableData: [{date: '2022-9-16'}],
      drawer: false,
      tableList: [],
      more: false
    }
  },
  mounted() {

    this.classShow();

  },
  methods: {
    classShow: function () {
      let that1 = this;
      this.axios.get('http://localhost:9090/user/getTrainClass/'+this.id)
          .then(function (ret) {
            that1.tableData = ret.data.data;
          })
    },
    tableShow(index, row) {
      this.drawer = true;
      let that = this;
      this.axios.get("http://localhost:9090/getDocuments/"+row.className)
          .then(res =>{
            console.log(res.data.data)
            that.tableList = res.data.data
            console.log(this.tableList)
          })
    },
    download(fileName,documentName){
      console.log(fileName);
      this.axios.get("http://localhost:9090/download",{params:{
          fileName:fileName
        }})
          .then(res =>{
            console.log(res.data)

            if (!res || res.size === 0) {
              Vue.prototype['$message'].warning('文件下载失败')
              return
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
              window.navigator.msSaveBlob(new Blob([res.data]), fileName)
            }
            else {
              let url = window.URL.createObjectURL(new Blob([res.data]))
              var aLink = document.createElement("a");
              aLink.style.display = "none";
              aLink.href = url;
              aLink.setAttribute("download", documentName);
              document.body.appendChild(aLink);
              aLink.click();
              document.body.removeChild(aLink); //下载完成移除元素
              window.URL.revokeObjectURL(url); //释放掉blob对象
            }


          }).catch(err =>{
        console.log(err)
      })
    },
  }
}
</script>

<style scoped>
/*表头*/
.container-fuild {

  float: left;
  /*padding-top:1.875rem;*/
  padding-right: 1.875rem;
  padding-left: 1.875rem;
  width: 93%;
  margin-right: auto;
  margin-left: auto;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.5;
  color: #7d94c0;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.page-titles {
  justify-content: space-between;
  /*padding: 0.1375rem 0.5rem;*/
  padding-top: 0.25rem;
  padding-right: 1.875rem;
  padding-bottom: 0.25rem;
  padding-left: 1.875rem;
  background: #fff;
  margin-bottom: 1.875rem;
  border-radius: 1rem;
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  --bs-gutter-x: 30px;
  --bs-gutter-y: 0;
  display: flex;
  flex-wrap: wrap;
}

.page-titles .breadcrumb {
  padding: 0;
  background: transparent;
  font-size: 1.1875rem;
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  list-style: none;
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
}

.breadcrumb li.active {
  font-weight: 600;
  font-size: 1.1875rem;
}

.breadcrumb li {
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 0.5rem;
  font-size: 1.1875rem;
}

/*主题部分*/
.row {
  --bs-gutter-x: 30px;
  --bs-gutter-y: 0;
  display: flex;
  flex-wrap: wrap;
  margin-top: calc(var(--bs-gutter-y) * -1);
  margin-right: calc(var(--bs-gutter-x) / -2);
  margin-left: calc(var(--bs-gutter-x) / -2);
}

.card {
  width: 100%;
  margin-bottom: 1.875rem;
  background-color: #fff;
  transition: all .5s ease-in-out;
  position: relative;
  border: 0rem solid transparent;
  border-radius: 1.25rem;
  box-shadow: 0rem 0.3125rem 0.3125rem 0rem rgb(82 63 105 / 5%);
  height: calc(100% - 30px);

  display: flex;
  flex-direction: column;
  min-width: 0;
  word-wrap: break-word;
  background-clip: border-box;
}

.card-header {
  border-color: #f5f5f5;
  position: relative;
  background: transparent;
  padding-right: 1.875rem;
  padding-left: 1.875rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  font-size: 1.1rem;
  font-weight: 300;
  color: #909399;
  text-transform: capitalize;
}

.card-body {
  padding-top: 0.125rem;
  padding-right: 1.875rem;
  padding-bottom: 1.125rem;
  padding-left: 1.875rem;

  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: auto;
}

.table-responsive-md {
  min-width: 36rem !important;
}

/*弹窗*/
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

/*让dialog能够悬浮在中间*/
.showAll_dialog {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
}

::v-deep .el-dialog {
  margin: 0 auto !important;
  height: 80%;
  overflow: auto;
  background-color: white;
}

.el-dialog__body {
  position: absolute;
  left: 0;
  top: 54px;
  bottom: 0;
  right: 0;
  z-index: 1;
  overflow: hidden;
  overflow-y: auto;

  line-height: 30px;
  padding: 15px;
}

.el-button--primary {
  background-color: #4682b4;
  border-color: #4682b4;
}

/*弹框步骤条的颜色*/
::v-deep .el-step__title.is-wait {
  color: #4682b4;
}

::v-deep .el-step__description.is-wait {
  color: #4682b4;
}

::v-deep .el-button {
  border-radius: 5px;
}

/*改变抽屉宽度*/
/deep/ .el-drawer {
  width: 315px !important;
}

</style>
